#ifndef __AW_NOOSLearnerBrain
#define __AW_NOOSLearnerBrain

class AW_NOOSLearnerBrain : public AW_NOOSBrain {
	
public:
	AW_NOOSLearnerBrain(Ontology *O,FTKBase *Memory,FTKBase *CB,bool pause);
	AW_NOOSLearnerBrain(FILE *fp,Ontology *O,FTKBase *Memory,FTKBase *CB,bool pause);

	~AW_NOOSLearnerBrain(); 

	virtual bool load(FILE *fp);
	virtual bool save(FILE *fp);

	virtual bool is_a(char *c);
	virtual bool is_a(Symbol *c);

	virtual void thread(void);


protected:

	virtual List<Symbol> *get_friends(void);

	virtual bool process_message(AW_Message *m,FeatureTerm *content);

	FeatureTerm *solve_problem_individually(FeatureTerm *problem,Sort *sort,Symbol *my_name);
	FeatureTerm *solve_problem_committee(FeatureTerm *problem,Sort *sort,Symbol *my_name);
	FeatureTerm *solve_problem_simple_committee(FeatureTerm *problem,Sort *sort,Symbol *my_name);
	FeatureTerm *solve_problem_bounded(FeatureTerm *problem,Sort *sort,Symbol *my_name);
	FeatureTerm *solve_problem_JEC(FeatureTerm *problem,Sort *sort,Symbol *my_name);
	FeatureTerm *solve_problem_IBA2A(FeatureTerm *problem,Sort *sort,Symbol *my_name,bool test);

	FeatureTerm *solve_problem_IBA_convener(FeatureTerm *problem,Sort *sort,Symbol *my_name,bool test);
	void solve_problem_IBA_other(FeatureTerm *problem,Sort *sort,Symbol *my_name,Symbol *convener_name,bool test);
	void IBA_compute_confidence(FeatureTerm *problem,List<FeatureTerm> *JERs,List<float> *JER_Cs,List<Symbol> *agent_names);
	float IBA_compute_confidence(FeatureTerm *problem,FeatureTerm *JERs,List<Symbol> *agent_names);
	FeatureTerm *IBA_generate_counterargument(FeatureTerm *problem,List<FeatureTerm> *JERs,List<float> *JER_Cs,Symbol *my_name,List<FeatureTerm> *self_JERs_historic,List<FeatureTerm> *self_CEs_historic);
	float local_confidence(FeatureTerm *JER,Sort *case_sort);

	FeatureTerm *solve_problem_JBartering(FeatureTerm *problem,Sort *sort,Symbol *my_name,bool test);
	void JBartering(FeatureTerm *solution,Sort *sort,Symbol *my_name,bool test);
	List<FeatureTerm> *JBartering_cases_to_offer(List< List<FeatureTerm> > *refutation_sets,int size);

	void JBartering_unfair(FeatureTerm *solution,Sort *sort,Symbol *my_name,bool test);
	void JBartering_nonstrict(FeatureTerm *solution,Sort *sort,Symbol *my_name,bool test);

	virtual FeatureTerm *build_jers(FeatureTerm *problem,Sort *sort,Symbol *agent_name);
	virtual FeatureTerm *build_single_jer(FeatureTerm *problem,Sort *sort,Symbol *agent_name);
	FeatureTerm *solve_problem_individually_without_IBA_cases(FeatureTerm *problem,Sort *sort,Symbol *agent_name);
	FeatureTerm *BWAV(List<FeatureTerm> *predictions);
	FeatureTerm *majority_voting(List<FeatureTerm> *predictions);

	FeatureTerm *examine_JER(FeatureTerm *JER,Sort *sort);

	FeatureTerm *generate_attacking_JER(FeatureTerm *problem,FeatureTerm *others_JER,List<FeatureTerm> *historic,Sort *sort,Symbol *agent_name);
	FeatureTerm *generate_counterexample(List<FeatureTerm> *not_allowd,FeatureTerm *others_JER,Sort *sort);

	bool bounded_halting_policy(List<FeatureTerm> *predictions);
	Symbol *bounded_next_agent_policy(List<Symbol> *agent_names,List<FeatureTerm> *predictions);

	void retain_cases(List<FeatureTerm> *cases,Symbol *strategy);
	void retain_case(FeatureTerm *c);


	Symbol *m_collaboration_strategy;
	Symbol *m_learning_method;
	Symbol *m_retention_strategy,*m_amal2_retention_strategy;
	bool m_generate_counterarguments;
	bool m_generate_counterexamples;

	List<FeatureTerm> JBartering_collected_JERs;

	List<Symbol> JBartering_refutationsets_agent_name;
	List< List< List<FeatureTerm> > > JBartering_refutationsets;

	List<FeatureTerm> already_sent_cases_IBA2A;
	List<FeatureTerm> received_cases_IBA2A;

	FeatureTerm *last_problem_solved;					// stores the last problem solved 

	List<int> BCCS_committe_size;						// stores the committee sizes
	List<int> CB_size;									// stores the CB size

	List<FeatureTerm> BCCS_CM_Candidate_Solution;		// stores the predictions of the competence models
	List<bool> BCCS_CM_Prediction;
	int BCCS_CM_accuracy[4];							// stores the number of TP,TN,FP and FN.

}; /* AW_NOOSLearnerBrain */ 

#endif

